﻿package com.PlantVsZombies.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;

import com.PlantVsZombies.common.Life;

import javazoom.jl.player.Player;

public class MP3Player extends Life {

	public MP3Player(String filename) {
		this.filename = filename;
	}

	public void play() {
		try {
			BufferedInputStream buffer = new BufferedInputStream(
					new FileInputStream(filename));
			player = new Player(buffer);
			player.play();
		} catch (Exception e) {
			System.out.println(e);
		}

	}

	public void Stop(){
		player.close();
		isAlive = false;
	}
	private String filename;
	private Player player;
	private boolean isAlive = true;

	public boolean getAlive() {
		return isAlive;
	}

	public void setAlive(boolean isAlive) {
		this.isAlive = isAlive;
	}


	@Override
	public int doRun() {
		// TODO Auto-generated method stub
		if(this.isAlive)
			this.play();
		else{
			return 0;
		}

		return 1;
	}
}